<include file="public@header"/>
<link href="__TMPL__/public/assets/themes/{:cmf_get_admin_style()}/house.css" rel="stylesheet">
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">帮助管理</a></li>
    </ul>

    <div class="help-index">
      <div class="list-wrap">
        <h4>帮助列表</h4>
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th width="50">ID</th>
                <th>标题</th>
                <th width="180">{:lang('ACTIONS')}</th>
            </tr>
            </thead>
            <tbody>
              <foreach name="list" item="item">
                <tr>
                  <td>{$item.id}</td>
                  <td>{$item.title}</td>
                  <td>
                    <a href="javascript:doEditParameter('{:url('edit',array('id'=>$item.id))}');">修改</a>
                    <a href="{:url('delete',array('id'=>$item['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                  </td>
                </tr>
              </foreach>
            </tbody>
        </table>
      </div>

      <div class="add-wrap">
        <div class="add">
          <h4>添加帮助</h4>
          <form action="addForm.html" class="js-ajax-form" method="post" name="addForm">
            <table class="table table-hover table-bordered">
              <tr>
                <td width="60">标题</td>
                <td>
                  <input class="form-control" type="text" name="title" value="">
                </td>
              </tr>
              <tr>
                <td>详情</td>
                <td>
                  <script type="text/plain" id="content" name="content"></script>
                </td>
              </tr>
            </table>
            <button class="btn btn-primary js-ajax-submit" type="submit" style="margin-left: 0px" data-loadingmsg="{:lang('LOADING')}">确认添加</button>
            <!-- <input type="submit" class="btn btn-primary js-ajax-submit" name="submit" value="添加"> -->
          </form>
        </div>
      </div>
    </div>
</div>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.frontend.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
  // 编辑器
  editorcontent = new baidu.editor.ui.Editor();
  editorcontent.render('content');
  try {
      editorcontent.sync();
  } catch (err) {
  }
});

function submit_check(event, data) {
  event.preventDefault();
  if (data.catid.value == 0) {
    alert('请选择参数类型！');
    return false;
  }

  if (data.name.value.trim() == '') {
    alert('请输入参数值！');
    return false;
  }

  var formData = {
    catid: data.catid.value,
    name: data.name.value
  }
  $.post('addForm.html', formData, function (res) {
    console.log(res)
  })
}

function doEditParameter(url) {
    openIframeLayer(url, '请选择分类', {
        area: ['50%', '80%'],
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //do something

            var iframeWin = window[layero.find('iframe')[0]['name']];
            var data = iframeWin.getForm();
            editForm(data.url, data.formData);

            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    });
};

function editForm (url, formData) {
  $.post(url, formData, function (data) {
    var _refresh = function() {
        if (data.url) {
            //返回带跳转地址
            window.location.href = data.url;
        } else {
            if (data.code == 1) {
                //刷新当前页
                reloadPage(window);
            }
        }
    }

    function _refresh() {
        if (data.url) {
            //返回带跳转地址
            window.location.href = data.url;
        } else {
            if (data.code == 1) {
                //刷新当前页
                reloadPage(window);
            }
        }
    }

    if (data.code == 1) {
        noty({
            text: data.msg,
            type: 'success',
            layout: 'topCenter',
            modal: true,
            // animation: {
            //     open: 'animated bounceInDown', // Animate.css class names
            //     close: 'animated bounceOutUp', // Animate.css class names
            // },
            timeout: 800,
            callback: {
                afterClose: function () {
                  _refresh();
                }
            }
        }).show();
        $(window).focus();
    } else if (data.code == 0) {
        noty({
            text: data.msg,
            type: 'error',
            layout: 'topCenter',
            modal: true,
            // animation: {
            //     open: 'animated bounceInDown', // Animate.css class names
            //     close: 'animated bounceOutUp', // Animate.css class names
            // },
            timeout: 800,
            callback: {
                afterClose: function () {
                    _refresh();
                }
            }
        }).show();
        $(window).focus();
    }
  })
};
</script>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
